#include <iostream>

using namespace std;
//浅拷贝与深拷贝
//浅拷贝: 简单的赋值拷贝操作
//深拷贝: 在堆区重新申请空间，进行拷贝操作

class Person {
public:
    int age;
    int *high;

    Person() {//无参构造
        cout << "默认构造函数的调用!" << endl;
    }

    Person(int age, int high) {//有参构造
        this->age = age;
        this->high = new int(high);
        cout << "有参构造函数的调用!" << endl;
    }

    Person(const Person &person) {//拷贝构造
        //this->height = person.height;//浅拷贝
        this->age = person.age;
        this->high = new int(*person.high);
        cout << "拷贝构造函数的调用!" << endl;
    }

    ~Person() {//析构函数
        //析构代码，将堆区开辟数据做释放操作
        if (high != nullptr) {
            delete high;
            high = nullptr;
        }
        cout << "析构函数的调用!" << endl;
    }
};

void test1() {
    Person person1(18, 160);
    cout << "person1:age=" << person1.age << ",high=" << *person1.high << endl;
    Person person2(person1);
    cout << "person2:age=" << person2.age << ",high=" << *person2.high << endl;
}

int main() {
    test1();
    return 0;
}